package com.finger.eduservice.controller;


import com.finger.commonutils.R;
import com.finger.eduservice.entity.subject.OneSubject;
import com.finger.eduservice.service.EduSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author finger
 * @since 2022-01-03
 */
@RestController
@RequestMapping("/eduservice/subject")
@CrossOrigin
public class EduSubjectController {

    @Autowired
    private EduSubjectService eduSubjectService;

    /**
     * 添加课程分类
     * @param file 上传的Excel文档
     * @return R
     */
    @PostMapping("/addSubject")
    public R addSubjectData(MultipartFile file){
        eduSubjectService.importSubjectData(file,eduSubjectService);
        return R.ok();
    }

    /**
     * 获取封装好的课程分类集合
     * @return
     */
    @GetMapping("/getSubjectTree")
    public R getSubjectTree(){
        List<OneSubject> subjectTree = eduSubjectService.getSubjectTree();
        return R.ok().data("list",subjectTree);
    }
}

